package edu.caece.langprocessor.lexical.tokens;

import java.util.HashMap;
import java.util.Map;

public enum TokenType {

	var("var"), identifier("identifier"), assignment(":="), kconst("const"), 
	numerical("numerical"), equals("="), greater(">"), greaterEquals(">="), 
	lower("<"), lowerEquals("<="), add("+"), subs("-"), mult("*"), div("/"), 
	begin("begin"), end("end"), kwhile("while"), kdo("do"), kif("if"), 
	then("then"), call("call"), procedure("procedure"), string("string"), 
	readln("readln"), writeln("writeln"), odd("odd"), even("even"), 
	endOfStatement(";"), separator(","), endOfProgram("."), leftParenthesis("("), 
	rightParenthesis(")"), endOfTree("$"), error("error"), write("write");

	private String value;

	TokenType(String value) {
		this.value = value;
	}

	public String getValue() {
		return this.value;
	}

	public static TokenType StringToTokenType(String value) {

		Map<String, TokenType> noValidValueOfTypes = new HashMap<String, TokenType>();	
		
		noValidValueOfTypes.put("const", TokenType.kconst);
		noValidValueOfTypes.put("do", TokenType.kdo);
		noValidValueOfTypes.put("while", TokenType.kwhile);
		noValidValueOfTypes.put("if", TokenType.kif);
		
		TokenType t = TokenType.error;
		
		if (noValidValueOfTypes.containsKey(value)){
			t = noValidValueOfTypes.get(value);
		}else{
			t = TokenType.valueOf(value);
		}
		return t;
	}
}
